package com.qiyue.admin.controller.base;

import com.qiyue.admin.biz.base.UserBiz;
import com.qiyue.admin.entity.base.User;
import com.qiyue.admin.rpc.service.PermissionService;
import com.qiyue.admin.vo.FrontUser;
import com.qiyue.admin.vo.MenuTree;
import com.qiyue.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with Intellij IDEA.
 * User : Yebinghuan
 * Created on 2018/1/23.
 * Description :
 */
@RestController
@RequestMapping("user")
@Api(value = "User",description = "用户")
public class UserController extends BaseController<UserBiz,User> {

    @Autowired
    private PermissionService permissionService;

    @GetMapping("/front/info")
    @ApiOperation("从token中获取userInfo")
    public ResponseEntity<?> getUserInfo(String token) throws Exception{

        FrontUser userInfo = permissionService.getUserInfo(token);
        if(userInfo==null) {
            return ResponseEntity.status(401).body(false);
        } else {
            return ResponseEntity.ok(userInfo);
        }
    }

    @GetMapping("/front/menus")
    @ApiOperation("通过 token 获取角色菜单")
    public List<MenuTree> getMenusByAccount(String token) {
        List<MenuTree> result= null;
        try {
            result = permissionService.getMenusByAccount(token);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


}
